﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CimeaSoft.BE;

namespace CimeaSoft.Repository
{
    public class MuestraResumenRepository:MasterRepository,IMuestraResumenRepository
    {
        public List<MuestraResumen> GetAllFromMuestraResumen()
        {
            var query = from c in context.MuestraResumens.Include("Muestra")
                        select c;
            return query.ToList();
        }

        public MuestraResumen GetAllFromMuestraResumenById(int id)
        {
            var query = from c in context.MuestraResumens.Include("Muestra")
                        where c.Id.Equals(id)
                        select c;
            return query.SingleOrDefault();
        }

        public void AddMuestraResumen(MuestraResumen muestraResumen)
        {
            muestraResumen.Muestra = null;
            context.MuestraResumens.Add(muestraResumen);
            context.SaveChanges();
        }


        public List<MuestraResumen> GetAllFromMuestraResumenByCriterio(string criterio)
        {
            var query = from c in context.MuestraResumens.Include("Muestra")
                        select c;
            if (criterio != null && criterio != string.Empty && criterio != "")
            {
                query = from c in context.MuestraResumens.Include("Muestra")
                        where c.Muestra.NumMuestra.Contains(criterio.ToUpper())
                        select c;
            }
            return query.ToList();
        }
    }
}
